import { IMenu } from "@/type/Menu";
import { useMenuStore } from "@/store/modules/Menu";
import request from "../api/request";

const getMenu = async () => {
  let roles = JSON.parse(localStorage.getItem('userInfo') || '{}').roles;
  const res = await request({
    url: '/menu',
    method: 'get',
  });
  let resData = res.data.menuList;
  if (roles.indexOf('admin') >= 0) {
    resData = resData.filter((item: IMenu) => item.title === '首页' || item.title === '超级表格');
  }
  const menuStore = useMenuStore();
  menuStore.setMenuList(resData);
  return {
    menuList: resData
  };
}
export default {
  getMenu
}